#ifndef __APP_BUFFER_H__
#define __APP_BUFFER_H__
#include <pthread.h>

#define APP_BUFF_SIZE 1024

/*子缓冲区 结构体*/
typedef struct 
{
    char* data_ptr;
    int total_len;
    int data_len;
}sub_buff_t;

/*主缓冲区结构体*/
typedef struct
{
    sub_buff_t* sub_buff_arr[2];  //子缓冲区指针数组
    int buff_read_index;        //读缓冲区标志
    int buff_write_index;       //写缓冲区标志
    pthread_mutex_t read_lock;  //读操作的锁
    pthread_mutex_t swap_lock;  //读写交换操作的锁
}buff_t;

/*主缓冲初始化*/
buff_t* App_buffer_Init(void);

/*向缓冲区中写入数据*/
int App_buffer_Write(buff_t* main_buff,char* data,int len);

/*从缓冲区中读取数据*/
int App_buffer_Read(buff_t* main_buff,char* data_buff,int len);

/*销毁缓冲区*/
void App_buffer_destroy(buff_t* buff);
#endif /* __APP_BUFFER_H__ */